import java.awt.Graphics;
import java.awt.Color;
import java.awt.Rectangle;


public class Missile {
	
	public static final int  WIDTH = 10;
	public static final int  HEIGHT = 10;
	private static final int XSPEED = 10;
	private static final int YSPEED = 10;
	
	int x, y;
	Direction dir;
	
	TankWar tankWar;
	
	private boolean live = true;
	
	public void setLive(boolean live) {
		this.live = live;
	}

	public boolean isLive() {
		return live;
	}

	public Missile(int x, int y, Direction dir){
		this.x = x;
		this.y = y;
		this.dir = dir;
	}
	
	
	
	public Missile(int x, int y, Direction dir, TankWar tankWar) {
		this(x, y, dir);
		this.tankWar = tankWar;
	}

	public void draw(Graphics g){
		Color c = g.getColor();
		g.setColor(Color.BLACK);
		g.fillOval(x, y, WIDTH, HEIGHT);
		g.setColor(c);
		
		move();
	}
	
	public void move(){
		switch(dir){
		case U:
			y -= YSPEED;
			break;
		case RU:
			x += XSPEED;
			y -= YSPEED;
			break;
		case R:
			x += XSPEED;
			break;
		case RD:
			x += XSPEED;
			y += YSPEED;
			break;
		case D:
			y += YSPEED;
			break;
		case LD:
			x -= XSPEED;
			y += YSPEED;
			break;
		case L:
			x -= XSPEED;
			break;
		case LU:
			x -= XSPEED;
			y -= YSPEED;
			break;
		}
		
		if(x<0 || y<0 || x>TankWar.GAME_WIDTH || y>TankWar.GAME_HEIGHT){
			live = false;
			tankWar.missiles.remove(this);
			
		}
	}
	
	public Rectangle getRectangle(){
		return new Rectangle(x, y, WIDTH, HEIGHT);
	}
}
